package com.huawei.petapp2.community;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ListView;

import com.huawei.petapp2.R;
import com.huawei.petapp2.constant.HttpAddress;
import com.huawei.petapp2.entity.Result;
import com.huawei.petapp2.entity.Store;
import com.huawei.petapp2.fragment.BaseFragment;
import com.huawei.petapp2.utils.DateUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.OnItemClick;

public class CommunityFragment extends BaseFragment {

   // private ListView shop_list;


    @BindView(R.id.shop_list)
     ListView shop_list;

    private ShopListAdapter shopListAdapter;

    private Context context;

    public View initView() {

        View view = View.inflate(context, R.layout.fragment_community, null);
        shop_list = view.findViewById(R.id.shop_list);
        return view;
    }

    @Override
    public void initView(View mView) {
        this.context=mView.getContext();
        shop_list = mView.findViewById(R.id.shop_list);
        initData();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_community;
    }

    @SuppressLint("NonConstantResourceId")
    @OnItemClick(R.id.shop_list)
    void onItemClick(int position) {
        System.out.println(position);
        chooseStore(position);
    }

    private void chooseStore(int position) {
        /*int categoryId = shopListAdapter.getItem(position).;
        navigateToSearch(categoryId);
        Intent intent = SearchGoodsActivity.getStartIntent(getContext(), categoryId);
        getActivity().startActivity(intent);*/
    }

    public void initData(){


        Result result = DateUtil.selectList(
                HttpAddress.get(HttpAddress.Store(),"listAll"));//获取首页的新品推荐

        List<Store> stores=DateUtil.getList12(result);

        System.out.println(stores);
        ShopListAdapter adapter = new ShopListAdapter(context, stores);




        /*ArrayList<Shop> shops = new ArrayList<>();
        Goods s1_goods1 = new Goods(R.drawable.xiaomi10,"小米10",2999.00);
        Goods s1_goods2 = new Goods(R.drawable.xiaomi10,"小米10 Pro",3999.00);
        Goods s1_goods3 = new Goods(R.drawable.xiaomi10,"小米10 Pro 12+512",4999.00);
        shops.add(new Shop(R.drawable.mi,"小米旗舰店",s1_goods1,s1_goods2,s1_goods3));

        Goods s2_goods1 = new Goods(R.drawable.ipad,"IPad2018金色",2599.00);
        Goods s2_goods2 = new Goods(R.drawable.ipad2,"IPad2018银色",2399.00);
        Goods s2_goods3 = new Goods(R.drawable.ipad3,"IPad Pro 11英寸",6999.00);
        shops.add(new Shop(R.drawable.apple,"Apple旗舰店",s2_goods1,s2_goods2,s2_goods3));*/

       // ShopListAdapter adapter = new ShopListAdapter(context, stores);
        shop_list.setAdapter(adapter);
    }




}
